package com.etc.myblog.ser;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.etc.myblog.biz.ReplyBiz;
import com.etc.myblog.entity.Comment;
import com.etc.myblog.entity.Reply;
import com.etc.myblog.entity.User;

public class ReplySer extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		ReplyBiz biz = new ReplyBiz();
		if (request.getParameter("tag") != null) {
			String tag = request.getParameter("tag");
			if (tag != "" && tag.equals("reply")) {
				String replyUserId = request.getParameter("replyUserId");
				String commId = request.getParameter("commId");
				String replyContent = request.getParameter("data_reply");
				String articleId = request.getParameter("articleId");
				if (replyUserId == null) {
					//request.getRequestDispatcher("ArticleSer?tag=detail").forward(request, response);
					response.sendRedirect("ArticleSer?tag=detail&articleid="+articleId);
					return;
				}
				Reply reply = new Reply();
				reply.setComment(new Comment(Integer.parseInt(commId)));
				reply.setUser(new User(Integer.parseInt(replyUserId)));
				reply.setReplyContent(replyContent);
				reply.setReplyTime(new Date());
				biz.addReply(reply);
				//request.setAttribute("reply", reply);
				response.sendRedirect("ArticleSer?tag=detail&articleid="+articleId);
			}
		}
	}

}
